/**
 * Copyright (c) 2011 Tomi Paananen.
 *
 * Part of Quick Gestures engine library.
 */

// Own header
#include "processingstoragemgr.h"

// qgengine includes
#include "featureextractor.h"
#include "gesture.h"
#include "qgcommon.h"
#include "qgtrace.h"
#include "xmlparser.h"

using namespace QGEngine;


/*!
  \class ProcessingStorageMgr
  \brief Extends the functionality of StorageManager by pre-processing every
         loaded gesture.
*/


/*!
  Constructor.
*/
ProcessingStorageMgr::ProcessingStorageMgr(QObject *parent /* = 0 */)
    : StorageManager(parent),
      m_featureExtractor(0)
{
    // Connect StorageManager::gestureRead() signal to processGesture() method
    // of this class.
    connect(this, SIGNAL(gestureRead(Gesture*)),
            this, SLOT(processGesture(Gesture*)));

    m_featureExtractor = new FeatureExtractor(this);
}


/*!
  Destructor.
*/
ProcessingStorageMgr::~ProcessingStorageMgr()
{
}


/*!
  Returns the feature extractor instance.
*/
FeatureExtractor *ProcessingStorageMgr::featureExtractor() const
{
    return m_featureExtractor;
}


/*!
  Pre-processes the parsed gesture using the feature extractor.
  Returns QGEngine::NoError if successful, an error code otherwise.
*/
int ProcessingStorageMgr::processGesture(Gesture *gesture)
{
    if (!gesture) {
        return InvalidArgument;
    }

    int error = m_featureExtractor->processGesture(gesture);

    if (error != NoError) {
        DEBUG_INFO("Failed to process gesture:" << error);
        return error;
    }

    emit gestureProcessed(gesture);
    return NoError;
}


// End of file.

